﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PingService.cs" company="Rabid Dog Labs">
//   Rabid Dog Labs
// </copyright>
// <summary>
//   Defines the PingService type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Net.NetworkInformation;

namespace TeamCommunitySolution.Modules.Network
{
    /// <summary>
    /// Service wrapping a ping mechanism.
    /// </summary>
    public class PingService
    {
        /// <summary>
        /// Pings the server.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <returns>value indicating if the server responded or not.</returns>
        public static bool PingServer(string server)
        {
            PingReply pingReply;

            using (Ping ping = new Ping())
            {
                pingReply = ping.Send(server);
            }

            bool available = false;

            if (pingReply != null)
            {
                available = pingReply.Status == IPStatus.Success;
            }

            return available;
        }
    }
}
